﻿using Microsoft.AspNetCore.Mvc;

namespace WebMvc.Controllers
{
    public class A01BaseController : Controller
    {
        private readonly ILogger<A01BaseController> _logger;

        public A01BaseController(ILogger<A01BaseController> logger)
        {
            _logger = logger;

            _logger.LogInformation($"LogInformation: {this.GetType().FullName} 被构造...");
            _logger.LogDebug($"LogDebug: {this.GetType().FullName} 被构造...");
            _logger.LogWarning($"LogWarning: {this.GetType().FullName} 被构造...");
            _logger.LogError($"LogError: {this.GetType().FullName} 被构造...");
        }

        /// <summary>
        /// 使用ViewData、ViewBag、TempData、Session和Model向视图传值
        /// 当ViewData和ViewBag中有相同key的值时，ViewBag中的值会覆盖ViewData中的值
        /// 
        /// [FromService] 注解指定对应形参使用IoC容器注入
        /// </summary>
        /// <returns></returns>
        public IActionResult Index([FromServices] ILogger<A01BaseController> logger)
        {
            ViewData["User1"] = "User1";
            ViewBag.User1 = "User1-1";
            ViewData["User2"] = "User2";
            TempData["User3"] = "User3";
            HttpContext.Session.SetString("User4", "User4");

            object user5 = "User5";

            return View(user5);
        }
    }
}
